﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace DBLootTrackerPlugin.ServiceModel
{
    public class LootTrackerDataService : ILootTrackerDataService
    {
        public static readonly List<ILootTrackerDataServiceCallbacks> subscribers = new List<ILootTrackerDataServiceCallbacks>();

        public bool Subscribe()
        {
            try
            {
                ILootTrackerDataServiceCallbacks callback = OperationContext.Current.GetCallbackChannel<ILootTrackerDataServiceCallbacks>();
                if (!subscribers.Contains(callback))
                {
                    subscribers.Add(callback);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Unsubscribe()
        {
            try
            {
                ILootTrackerDataServiceCallbacks callback = OperationContext.Current.GetCallbackChannel<ILootTrackerDataServiceCallbacks>();
                if (subscribers.Contains(callback))
                {
                    subscribers.Remove(callback);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }


        public bool IsAlive()
        {
            return true;
        }
    }
}
